package com.week.tiny_video.service.impl;

import com.week.tiny_video.dao.AdministratorDao;
import com.week.tiny_video.pojo.Administrator;
import com.week.tiny_video.service.AdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdministratorServiceImpl implements AdministratorService {

    @Autowired
    private AdministratorDao administratorDao;

    @Override
    public boolean isExist(String username) {
        Administrator administrator = getByName(username);
        return null != administrator;
    }

    @Override
    public Administrator getByName(String username) {
        return administratorDao.findByUsername(username);
    }

    @Override
    public Administrator get(String username, String password) {
        return administratorDao.getByUsernameAndPassword(username,password);
    }

    @Override
    public void add(Administrator administrator) {
        administratorDao.save(administrator);
    }

    @Override
    public List<Administrator> list() {
        return administratorDao.findAll();
    }

    @Override
    public Administrator getById(int id) {
        return administratorDao.findById(id).orElse(null);
    }

    @Override
    public void delete(int id) {
        administratorDao.deleteById(id);
    }
}
